namespace Cofe.Data.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.DatabaseEntry",
                c => new
                    {
                        Id = c.Guid(nullable: false, identity: true),
                        ParseName = c.String(nullable: false, maxLength: 512),
                        Label = c.String(nullable: false, maxLength: 128),
                        OriginalType = c.String(),
                        Description = c.String(),
                        SupportedProperties = c.String(nullable: false, maxLength: 2048),
                        SupportDefinitions = c.String(nullable: false, maxLength: 1024),
                        DefaultEntryType = c.String(),
                        LastCacheTime = c.DateTime(nullable: false),
                        LastListTime = c.DateTime(nullable: false),
                        ParentId = c.Guid(),
                        EntryTypeInfoId = c.Guid(),
                        LinkedEntryId = c.Guid(),
                        DBVolumeInfo_VolumeId = c.String(maxLength: 128),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.DatabaseEntry", t => t.EntryTypeInfoId)
                .ForeignKey("dbo.DatabaseEntry", t => t.LinkedEntryId)
                .ForeignKey("dbo.DatabaseEntry", t => t.ParentId)
                .ForeignKey("dbo.Volumes", t => t.DBVolumeInfo_VolumeId)
                .Index(t => t.EntryTypeInfoId)
                .Index(t => t.LinkedEntryId)
                .Index(t => t.ParentId)
                .Index(t => t.DBVolumeInfo_VolumeId);
            
            CreateTable(
                "dbo.HashTag",
                c => new
                    {
                        TagName = c.String(nullable: false, maxLength: 64),
                        TagType = c.String(maxLength: 64),
                    })
                .PrimaryKey(t => t.TagName);
            
            CreateTable(
                "dbo.PropertyPair",
                c => new
                    {
                        PropertyId = c.Int(nullable: false),
                        EntityId = c.Guid(nullable: false),
                        ValueRetrieveTime = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => new { t.PropertyId, t.EntityId })
                .ForeignKey("dbo.DatabaseEntry", t => t.EntityId, cascadeDelete: true)
                .Index(t => t.EntityId);
            
            CreateTable(
                "dbo.CofeSystemInfo",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Type = c.String(nullable: false, maxLength: 50),
                        CofeAttributes = c.Int(nullable: false),
                        Position = c.Int(),
                    })
                .PrimaryKey(t => new { t.Id, t.Type })
                .ForeignKey("dbo.DatabaseEntry", t => t.Id, cascadeDelete: true)
                .Index(t => t.Id);
            
            CreateTable(
                "dbo.CofeSystemEvents",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        UserId = c.String(),
                        Sender = c.String(),
                        Time = c.DateTime(nullable: false),
                        EntryId = c.Guid(),
                        EntryParsePath = c.String(),
                        IsFolder = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Volumes",
                c => new
                    {
                        VolumeId = c.String(nullable: false, maxLength: 128),
                        FactoryId = c.String(),
                        ParamString = c.String(),
                    })
                .PrimaryKey(t => t.VolumeId);
            
            CreateTable(
                "dbo.HashTag_Entries",
                c => new
                    {
                        TagName = c.String(nullable: false, maxLength: 64),
                        EntryId = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => new { t.TagName, t.EntryId })
                .ForeignKey("dbo.HashTag", t => t.TagName, cascadeDelete: true)
                .ForeignKey("dbo.DatabaseEntry", t => t.EntryId, cascadeDelete: true)
                .Index(t => t.TagName)
                .Index(t => t.EntryId);
            
            CreateTable(
                "dbo.EntryTypeInfo",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Type = c.String(nullable: false, maxLength: 50),
                        EntryTypeKey = c.String(),
                        SmallIcon = c.Binary(),
                        LargeIcon = c.Binary(),
                        ExtraLargeIcon = c.Binary(),
                        JumboIcon = c.Binary(),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.Id, t.Type })
                .ForeignKey("dbo.CofeSystemInfo", t => new { t.Id, t.Type }, cascadeDelete: true)
                .Index(t => new { t.Id, t.Type });
            
            CreateTable(
                "dbo.CofeDirectoryInfo",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Type = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => new { t.Id, t.Type })
                .ForeignKey("dbo.CofeSystemInfo", t => new { t.Id, t.Type }, cascadeDelete: true)
                .Index(t => new { t.Id, t.Type });
            
            CreateTable(
                "dbo.CofeItemInfo",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Type = c.String(nullable: false, maxLength: 50),
                        Length = c.Long(nullable: false),
                    })
                .PrimaryKey(t => new { t.Id, t.Type })
                .ForeignKey("dbo.CofeSystemInfo", t => new { t.Id, t.Type }, cascadeDelete: true)
                .Index(t => new { t.Id, t.Type });
            
            CreateTable(
                "dbo.CustomEntryList",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Type = c.String(nullable: false, maxLength: 50),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.Id, t.Type })
                .ForeignKey("dbo.CofeDirectoryInfo", t => new { t.Id, t.Type }, cascadeDelete: true)
                .Index(t => new { t.Id, t.Type });
            
            CreateTable(
                "dbo.AutoEntryList",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Type = c.String(nullable: false, maxLength: 50),
                        EntryFilterString = c.String(),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.Id, t.Type })
                .ForeignKey("dbo.CofeDirectoryInfo", t => new { t.Id, t.Type }, cascadeDelete: true)
                .Index(t => new { t.Id, t.Type });
            
            CreateTable(
                "dbo.EntryLink",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        Type = c.String(nullable: false, maxLength: 50),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.Id, t.Type })
                .ForeignKey("dbo.CofeSystemInfo", t => new { t.Id, t.Type }, cascadeDelete: true)
                .Index(t => new { t.Id, t.Type });
            
            CreateTable(
                "dbo.CofeSystemChangeEvents",
                c => new
                    {
                        Id = c.Int(nullable: false),
                        ChangeType = c.Short(nullable: false),
                        OldParsePath = c.String(),
                        Type = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.CofeSystemEvents", t => t.Id, cascadeDelete: true)
                .Index(t => t.Id);
            
            CreateTable(
                "dbo.CofeSystemActionEvents",
                c => new
                    {
                        Id = c.Int(nullable: false),
                        ActionCalled = c.Int(nullable: false),
                        Type = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.CofeSystemEvents", t => t.Id, cascadeDelete: true)
                .Index(t => t.Id);
            
            CreateTable(
                "dbo.PropertyPair_Double",
                c => new
                    {
                        PropertyId = c.Int(nullable: false),
                        EntityId = c.Guid(nullable: false),
                        ORMValue = c.Double(nullable: false),
                        Type = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.PropertyId, t.EntityId })
                .ForeignKey("dbo.PropertyPair", t => new { t.PropertyId, t.EntityId }, cascadeDelete: true)
                .Index(t => new { t.PropertyId, t.EntityId });
            
            CreateTable(
                "dbo.PropertyPair_Int16",
                c => new
                    {
                        PropertyId = c.Int(nullable: false),
                        EntityId = c.Guid(nullable: false),
                        ORMValue = c.Short(nullable: false),
                        Type = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.PropertyId, t.EntityId })
                .ForeignKey("dbo.PropertyPair", t => new { t.PropertyId, t.EntityId }, cascadeDelete: true)
                .Index(t => new { t.PropertyId, t.EntityId });
            
            CreateTable(
                "dbo.PropertyPair_Int32",
                c => new
                    {
                        PropertyId = c.Int(nullable: false),
                        EntityId = c.Guid(nullable: false),
                        ORMValue = c.Int(nullable: false),
                        Type = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.PropertyId, t.EntityId })
                .ForeignKey("dbo.PropertyPair", t => new { t.PropertyId, t.EntityId }, cascadeDelete: true)
                .Index(t => new { t.PropertyId, t.EntityId });
            
            CreateTable(
                "dbo.PropertyPair_Int64",
                c => new
                    {
                        PropertyId = c.Int(nullable: false),
                        EntityId = c.Guid(nullable: false),
                        ORMValue = c.Long(nullable: false),
                        Type = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.PropertyId, t.EntityId })
                .ForeignKey("dbo.PropertyPair", t => new { t.PropertyId, t.EntityId }, cascadeDelete: true)
                .Index(t => new { t.PropertyId, t.EntityId });
            
            CreateTable(
                "dbo.PropertyPair_DateTime",
                c => new
                    {
                        PropertyId = c.Int(nullable: false),
                        EntityId = c.Guid(nullable: false),
                        ORMValue = c.DateTime(nullable: false),
                        Type = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.PropertyId, t.EntityId })
                .ForeignKey("dbo.PropertyPair", t => new { t.PropertyId, t.EntityId }, cascadeDelete: true)
                .Index(t => new { t.PropertyId, t.EntityId });
            
            CreateTable(
                "dbo.PropertyPair_Bool",
                c => new
                    {
                        PropertyId = c.Int(nullable: false),
                        EntityId = c.Guid(nullable: false),
                        ORMValue = c.Boolean(nullable: false),
                        Type = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.PropertyId, t.EntityId })
                .ForeignKey("dbo.PropertyPair", t => new { t.PropertyId, t.EntityId }, cascadeDelete: true)
                .Index(t => new { t.PropertyId, t.EntityId });
            
            CreateTable(
                "dbo.PropertyPair_Guid",
                c => new
                    {
                        PropertyId = c.Int(nullable: false),
                        EntityId = c.Guid(nullable: false),
                        ORMValue = c.Guid(nullable: false),
                        Type = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.PropertyId, t.EntityId })
                .ForeignKey("dbo.PropertyPair", t => new { t.PropertyId, t.EntityId }, cascadeDelete: true)
                .Index(t => new { t.PropertyId, t.EntityId });
            
            CreateTable(
                "dbo.PropertyPair_String",
                c => new
                    {
                        PropertyId = c.Int(nullable: false),
                        EntityId = c.Guid(nullable: false),
                        ORMValue = c.String(),
                        Type = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.PropertyId, t.EntityId })
                .ForeignKey("dbo.PropertyPair", t => new { t.PropertyId, t.EntityId }, cascadeDelete: true)
                .Index(t => new { t.PropertyId, t.EntityId });
            
            CreateTable(
                "dbo.PropertyPair_ByteArray",
                c => new
                    {
                        PropertyId = c.Int(nullable: false),
                        EntityId = c.Guid(nullable: false),
                        ORMValue = c.Binary(),
                        Type = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.PropertyId, t.EntityId })
                .ForeignKey("dbo.PropertyPair", t => new { t.PropertyId, t.EntityId }, cascadeDelete: true)
                .Index(t => new { t.PropertyId, t.EntityId });
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.PropertyPair_ByteArray", new[] { "PropertyId", "EntityId" });
            DropIndex("dbo.PropertyPair_String", new[] { "PropertyId", "EntityId" });
            DropIndex("dbo.PropertyPair_Guid", new[] { "PropertyId", "EntityId" });
            DropIndex("dbo.PropertyPair_Bool", new[] { "PropertyId", "EntityId" });
            DropIndex("dbo.PropertyPair_DateTime", new[] { "PropertyId", "EntityId" });
            DropIndex("dbo.PropertyPair_Int64", new[] { "PropertyId", "EntityId" });
            DropIndex("dbo.PropertyPair_Int32", new[] { "PropertyId", "EntityId" });
            DropIndex("dbo.PropertyPair_Int16", new[] { "PropertyId", "EntityId" });
            DropIndex("dbo.PropertyPair_Double", new[] { "PropertyId", "EntityId" });
            DropIndex("dbo.CofeSystemActionEvents", new[] { "Id" });
            DropIndex("dbo.CofeSystemChangeEvents", new[] { "Id" });
            DropIndex("dbo.EntryLink", new[] { "Id", "Type" });
            DropIndex("dbo.AutoEntryList", new[] { "Id", "Type" });
            DropIndex("dbo.CustomEntryList", new[] { "Id", "Type" });
            DropIndex("dbo.CofeItemInfo", new[] { "Id", "Type" });
            DropIndex("dbo.CofeDirectoryInfo", new[] { "Id", "Type" });
            DropIndex("dbo.EntryTypeInfo", new[] { "Id", "Type" });
            DropIndex("dbo.HashTag_Entries", new[] { "EntryId" });
            DropIndex("dbo.HashTag_Entries", new[] { "TagName" });
            DropIndex("dbo.CofeSystemInfo", new[] { "Id" });
            DropIndex("dbo.PropertyPair", new[] { "EntityId" });
            DropIndex("dbo.DatabaseEntry", new[] { "DBVolumeInfo_VolumeId" });
            DropIndex("dbo.DatabaseEntry", new[] { "ParentId" });
            DropIndex("dbo.DatabaseEntry", new[] { "LinkedEntryId" });
            DropIndex("dbo.DatabaseEntry", new[] { "EntryTypeInfoId" });
            DropForeignKey("dbo.PropertyPair_ByteArray", new[] { "PropertyId", "EntityId" }, "dbo.PropertyPair");
            DropForeignKey("dbo.PropertyPair_String", new[] { "PropertyId", "EntityId" }, "dbo.PropertyPair");
            DropForeignKey("dbo.PropertyPair_Guid", new[] { "PropertyId", "EntityId" }, "dbo.PropertyPair");
            DropForeignKey("dbo.PropertyPair_Bool", new[] { "PropertyId", "EntityId" }, "dbo.PropertyPair");
            DropForeignKey("dbo.PropertyPair_DateTime", new[] { "PropertyId", "EntityId" }, "dbo.PropertyPair");
            DropForeignKey("dbo.PropertyPair_Int64", new[] { "PropertyId", "EntityId" }, "dbo.PropertyPair");
            DropForeignKey("dbo.PropertyPair_Int32", new[] { "PropertyId", "EntityId" }, "dbo.PropertyPair");
            DropForeignKey("dbo.PropertyPair_Int16", new[] { "PropertyId", "EntityId" }, "dbo.PropertyPair");
            DropForeignKey("dbo.PropertyPair_Double", new[] { "PropertyId", "EntityId" }, "dbo.PropertyPair");
            DropForeignKey("dbo.CofeSystemActionEvents", "Id", "dbo.CofeSystemEvents");
            DropForeignKey("dbo.CofeSystemChangeEvents", "Id", "dbo.CofeSystemEvents");
            DropForeignKey("dbo.EntryLink", new[] { "Id", "Type" }, "dbo.CofeSystemInfo");
            DropForeignKey("dbo.AutoEntryList", new[] { "Id", "Type" }, "dbo.CofeDirectoryInfo");
            DropForeignKey("dbo.CustomEntryList", new[] { "Id", "Type" }, "dbo.CofeDirectoryInfo");
            DropForeignKey("dbo.CofeItemInfo", new[] { "Id", "Type" }, "dbo.CofeSystemInfo");
            DropForeignKey("dbo.CofeDirectoryInfo", new[] { "Id", "Type" }, "dbo.CofeSystemInfo");
            DropForeignKey("dbo.EntryTypeInfo", new[] { "Id", "Type" }, "dbo.CofeSystemInfo");
            DropForeignKey("dbo.HashTag_Entries", "EntryId", "dbo.DatabaseEntry");
            DropForeignKey("dbo.HashTag_Entries", "TagName", "dbo.HashTag");
            DropForeignKey("dbo.CofeSystemInfo", "Id", "dbo.DatabaseEntry");
            DropForeignKey("dbo.PropertyPair", "EntityId", "dbo.DatabaseEntry");
            DropForeignKey("dbo.DatabaseEntry", "DBVolumeInfo_VolumeId", "dbo.Volumes");
            DropForeignKey("dbo.DatabaseEntry", "ParentId", "dbo.DatabaseEntry");
            DropForeignKey("dbo.DatabaseEntry", "LinkedEntryId", "dbo.DatabaseEntry");
            DropForeignKey("dbo.DatabaseEntry", "EntryTypeInfoId", "dbo.DatabaseEntry");
            DropTable("dbo.PropertyPair_ByteArray");
            DropTable("dbo.PropertyPair_String");
            DropTable("dbo.PropertyPair_Guid");
            DropTable("dbo.PropertyPair_Bool");
            DropTable("dbo.PropertyPair_DateTime");
            DropTable("dbo.PropertyPair_Int64");
            DropTable("dbo.PropertyPair_Int32");
            DropTable("dbo.PropertyPair_Int16");
            DropTable("dbo.PropertyPair_Double");
            DropTable("dbo.CofeSystemActionEvents");
            DropTable("dbo.CofeSystemChangeEvents");
            DropTable("dbo.EntryLink");
            DropTable("dbo.AutoEntryList");
            DropTable("dbo.CustomEntryList");
            DropTable("dbo.CofeItemInfo");
            DropTable("dbo.CofeDirectoryInfo");
            DropTable("dbo.EntryTypeInfo");
            DropTable("dbo.HashTag_Entries");
            DropTable("dbo.Volumes");
            DropTable("dbo.CofeSystemEvents");
            DropTable("dbo.CofeSystemInfo");
            DropTable("dbo.PropertyPair");
            DropTable("dbo.HashTag");
            DropTable("dbo.DatabaseEntry");
        }
    }
}
